home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / utils / refer-tools / ref2bib.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1994-11-13  |  18KB  |  732 lines

  1. #!/bin/sh
  2. #
  3. #    shell script to convert refer (or bib) databases to BiBTeX format
  4. #
  5. #    reads its arguments (or standard input)
  6. #    and writes the BibTeX to standard output
  7. #
  8. #    the in-line files ref2b*.{sed,awk} do not change, and could be
  9. #    stored in a library somewhere.  The sed script can actually be
  10. #    given as an argument in ' ' quotes provided the ' in the
  11. #    file are replaced with '\'' !!
  12. #    the awk script is too large for this treatment.
  13. #
  14. #    The gnereation of keys can be altered by changing the
  15. #    values of some awk variables
  16. #
  17. #    errors etc. in ref2bib.errs
  18. #
  19. cat << 'ZZ' >ref2b$$.sed
  20. #
  21. # sed script to do some of the ref to bib database conversion
  22. #
  23. # written by Peter King, Heriot-Watt University
  24. # You may do anything you like with this code
  25. # EXCEPT claim that you wrote it
  26. #
  27. # First alter the TeX special characters
  28. s/\(.\)%/\1\\%/g
  29. s/&/\\&/g
  30. s/\$/\\$/g
  31. s/#/\\#/g
  32. s/_/\\_/g
  33. s/{/\\{/g
  34. s/}/\\}/g
  35. # convert the special characters and accents from troff to BibTeX
  36. # assumes the accents are those of the Berkeley -ms with .AM
  37. #
  38. /\\/s/\(.\)\\\\*\*'/{\\'\1}/g
  39. /\\/s/\(.\)\\\\*\*`/{\\`\1}/g
  40. /\\/s/\(.\)\\\\*\*^/{\\^\1}/g
  41. /\\/s/\(.\)\\\\*\*:/{\\"\1}/g
  42. /\\/s/\(.\)\\\\*\*~/{\\~\1}/g
  43. /\\/s/\(.\)\\\\*\*_/{\\=\1}/g
  44. /\\/s/\([oO]\)\\\\*\*\//{\\\1}/g
  45. /\\/s/\([aA]\)\\\\*\*o/{\\\1\1}/g
  46. /\\/s/\(.\)\\\\*\*,/{\\c{\1}}/g
  47. /\\/s/\(.\)\\\\*\*v/{\\v{\1}}/g
  48. /\\/s/\(.\)\\\\*\*"/{\\H{\1}}/g
  49. /\\/s/\(.\)\\\\*\*\./{\\d{\1}}/g
  50. /\\/s/\\\\*\*8/{\\ss}/g
  51. /\\/s/\\\\*\*(P\([lL]\)/{\\\1}/g
  52. /\\/s/\\\\*\*(\([oO]\)\//{\\\1}/g
  53. # quotes
  54. /\\/s/\\\\*\*Q/``/g
  55. /\\/s/\\\\*\*U/''/g
  56. /\\/s/\\\\*\*-/---/g
  57. # \0 as space between surname de\0Souza etc.
  58. /\\/s/\\\\*0\([a-z]*\)\\\\*0/\\0\1 /g
  59. /\\/s/ \([a-z]*\)\\\\*0/ \1 /g
  60. # but trap the ones that start with a capital letter and convert them to
  61. # ties
  62. /\\/s/\\\\*0/~/g
  63. #
  64. # now deal with special characters and Greek
  65. /\\/s/\\\\*(em/---/g
  66. /\\/s/\\\\*(if/$\\infty$/g
  67. /\\/s/\\\\*(\*a/$\\alpha$/g
  68. /\\/s/\\\\*(\*b/$\\beta$/g
  69. /\\/s/\\\\*(\*g/$\\gamma$/g
  70. /\\/s/\\\\*(\*d/$\\delta$/g
  71. /\\/s/\\\\*(\*e/$\\epsilon$/g
  72. /\\/s/\\\\*(\*z/$\\zeta$/g
  73. /\\/s/\\\\*(\*y/$\\eta$/g
  74. /\\/s/\\\\*(\*h/$\\theta$/g
  75. /\\/s/\\\\*(\*i/$\\iota$/g
  76. /\\/s/\\\\*(\*k/$\\kappa$/g
  77. /\\/s/\\\\*(\*l/$\\lambda$/g
  78. /\\/s/\\\\*(\*m/$\\mu$/g
  79. /\\/s/\\\\*(\*n/$\\nu$/g
  80. /\\/s/\\\\*(\*c/$\\xi$/g
  81. /\\/s/\\\\*(\*o/$o$/g
  82. /\\/s/\\\\*(\*p/$\\pi$/g
  83. /\\/s/\\\\*(\*r/$\\rho$/g
  84. /\\/s/\\\\*(\*s/$\\sigma$/g
  85. /\\/s/\\\\*(\*t/$\\tau$/g
  86. /\\/s/\\\\*(\*u/$\\upsilon$/g
  87. /\\/s/\\\\*(\*f/$\\phi$/g
  88. /\\/s/\\\\*(\*x/$\\chi$/g
  89. /\\/s/\\\\*(\*q/$\\psi$/g
  90. /\\/s/\\\\*(\*w/$\\omega$/g
  91. /\\/s/\\\\*(\*A/A/g
  92. /\\/s/\\\\*(\*B/B/g
  93. /\\/s/\\\\*(\*G/$\\Gamma$/g
  94. /\\/s/\\\\*(\*D/$\\Delta$/g
  95. /\\/s/\\\\*(\*E/E/g
  96. /\\/s/\\\\*(\*Z/Z/g
  97. /\\/s/\\\\*(\*Y/H/g
  98. /\\/s/\\\\*(\*H/$\\Theta$/g
  99. /\\/s/\\\\*(\*I/I/g
  100. /\\/s/\\\\*(\*K/K/g
  101. /\\/s/\\\\*(\*L/$\\Lambda$/g
  102. /\\/s/\\\\*(\*M/M/g
  103. /\\/s/\\\\*(\*N/N/g
  104. /\\/s/\\\\*(\*C/$\\Xi$/g
  105. /\\/s/\\\\*(\*O/$O$/g
  106. /\\/s/\\\\*(\*P/$\\Pi$/g
  107. /\\/s/\\\\*(\*R/P/g
  108. /\\/s/\\\\*(\*S/$\\Sigma$/g
  109. /\\/s/\\\\*(\*T/T/g
  110. /\\/s/\\\\*(\*U/$\\Upsilon$/g
  111. /\\/s/\\\\*(\*F/$\\Phi$/g
  112. /\\/s/\\\\*(\*X/X/g
  113. /\\/s/\\\\*(\*Q/$\\Psi$/g
  114. /\\/s/\\\\*(\*W/$\\Omega$/g
  115. # Now trap title words that must be capitalised
  116. /^%[^T]/b
  117. #
  118. # first all words that are all capitals (at least two consecutive)
  119. # we need the slashes to allow for M/M/1 queues
  120. s;[A-Z][A-Z/][A-Z/0-9]*;{&};g
  121. #
  122. # then some proper names
  123. # first some mathematicians
  124. # (for some I've added the Pattern [^ -]* toe the end to get Markov,
  125. # Markovian, etc.
  126. s/Abel/{&}/g
  127. s/Bernoulli/{&}/g
  128. s/Bessel/{&}/g
  129. s/Beta/{&}/g
  130. s/Borel/{&}/g
  131. s/Cauchy/{&}/g
  132. s/Church/{&}/g
  133. s/Rosser/{&}/g
  134. s/Dedekind/{&}/g
  135. s/Descartes/{&}/g
  136. s/Dirichlet/{&}/g
  137. s/Euclid[^ -,;]*/{&}/g
  138. s/Euler/{&}/g
  139. s/Fibonacci/{&}/g
  140. s/Fermat/{&}/g
  141. s/Fourier/{&}/g
  142. s/Fresnel/{&}/g
  143. s/Frobenius/{&}/g
  144. s/Perron/{&}/g
  145. s/Gamma/{&}/g
  146. s/Gauss[^ -,;]*/{&}/g
  147. s/Hilbert/{&}/g
  148. s/Horner/{&}/g
  149. s/Holder/{&}/g
  150. s/Jacobi[^ -,;]*/{&}/g
  151. s/Jensen/{&}/g
  152. s/Markov[^ -,;]*/{&}/g
  153. s/Arnoldi/{&}/g
  154. s/Laplace/{&}/g
  155. s/Laguerre/{&}/g
  156. s/Lagrange/{&}/g
  157. s/Legendre/{&}/g
  158. s/Leibnitz/{&}/g
  159. s/Rayleigh/{&}/g
  160. s/Ritz/{&}/g
  161. s/Riemann/{&}/g
  162. # this is really Rouche (acute accent) , but the accent processing will disrupt it
  163. s/Rouch/{&}/g
  164. s/Stieltjes/{&}/g
  165. s/Stiener/{&}/g
  166. s/Schwarz/{&}/g
  167. s/Weibull/{&}/g
  168. s/Wald/{&}/g
  169. s/Kronecker/{&}/g
  170. s/Diophantine/{&}/g
  171. s/Delbrouck/{&}/g
  172. s/Bayes[^ -,;]*/{&}/g
  173. s/Jackson/{&}/g
  174. s/Newhall/{&}/g
  175. s/Turing/{&}/g
  176. s/Norton/{&}/g
  177. s/Petri/{&}/g
  178. s/Wilkinson/{&}/g
  179. s/Skinner/{&}/g
  180. s/Schafer/{&}/g
  181. s/Dempster/{&}/g
  182. s/Runge/{&}/g
  183. s/Kutta/{&}/g
  184. s/Pollaczek/{&}/g
  185. s/Khinchin/{&}/g
  186. s/Palm/{&}/g
  187. s/Erlang/{&}/g
  188. s/Engset/{&}/g
  189. s/Little's/{&}/g
  190. s/Kosten/{&}/g
  191. s/Gittins/{&}/g
  192. s/Feller/{&}/g
  193. s/Cox/{&}/g
  194. s/Poisson/{&}/g
  195. s/Chapman/{&}/g
  196. s/Kolmogorov/{&}/g
  197. s/Smirnov/{&}/g
  198. s/Weiner/{&}/g
  199. s/Hopf/{&}/g
  200. s/Stirling/{&}/g
  201.  
  202. # computing
  203. s/Buzen/{&}/g
  204. s/Gordon/{&}/g
  205. s/Newell/{&}/g
  206. s/Lemoine/{&}/g
  207. s/Pierce/{&}/g
  208. s/Harrison/{&}/g
  209. s/Cambridge/{&}/g
  210. s/Ethernet/{&}/g
  211. s/Aloha/{&}/g
  212.  
  213. # coding theory
  214. s/Hamming/{&}/g
  215. s/Huffman/{&}/g
  216. s/Reed/{&}/g
  217. s/Shannon/{&}/g
  218. s/Solomon/{&}/g
  219. s/Viterbi/{&}/g
  220. ZZ
  221. cat << 'ZZ' > ref2b$$.awk
  222. #
  223. #    awk script to convert refer (or bib) format databases
  224. #    to BiBTeX format.
  225. #
  226. #    written by Peter King, Heriot-Watt University
  227. #    use freely, but dont claim that you wrote it
  228. #
  229. #    Generates keys using authors names and year (see %A entry )
  230. #    
  231. #    You may wish to alter treatment of key fields that are ignored
  232. #    such as %U %W %Y %K etc.
  233. #
  234. #  regular expressions should be sorted according to frequency 
  235. #  so that minimal tests are made
  236. #  From tests in a local data base the order given appears quite good
  237. #    2883 %A
  238. #    1813   blank lines
  239. #    1774 %T
  240. #    1764 %D
  241. #    1505 %P
  242. #    1347 %J
  243. #    1331 %V
  244. #    1201 %N
  245. #    773 .. continuation lines
  246. #    501 %C
  247. #    424 %I
  248. #    192 %B
  249. #    187 %E
  250. #    92 %S
  251. #    89 %R
  252. #    33 %X
  253. #    30 %K
  254. #    16 %O
  255. #    12 %any other % lines
  256. #
  257. BEGIN    {
  258.     for(i=1;i<=27;i++)
  259.         addkey[i] = substr(" abcdefghijklmnopqrstuvwxyz",i,1);
  260.     lkey = 3; # number of characters used from authors to make key
  261.     maxauthor = 3; # maximum number of authors to use in
  262.             # constructing key
  263.     rx = 1
  264.     }
  265.  
  266. /\\[*u0]/ || /\\d[^{]/|| /\\s[^s]/ {
  267.     err = 1
  268.     print "Non translated \\ symbol : Reference " rx > "ref2bib.errs"
  269.     print  $0 > "ref2bib.errs"
  270.     }
  271.  
  272. /^%A/    {
  273.     if (A==0) keys="";
  274.     A ++; lastx = "A"; 
  275.     authors[A] = substr($0,4)
  276.     if(A> maxauthor) next
  277.     ic = 0
  278.     lc = 1
  279.     while(ic < lkey && lc <= length($NF) ){
  280.         kc = substr( $NF, lc, 1)
  281.         if ( kc ~ /[a-zA-Z]/ ){
  282.             keys = keys kc
  283.             ic++
  284.             if(ic==lkey) next
  285.             }
  286.         else if ( kc == "\\" ) lc ++;
  287.         lc ++;
  288.         }
  289.     next
  290.     }
  291.  
  292. /^$/    {
  293.     if(NR==pr+1){
  294.         }
  295.     else {
  296.     refs ++
  297.     # if FILENAME != prevname then new file
  298.     acnt[A]++;if(A>MaxA)MaxA=A;
  299.     if(T==0)print "No title : Reference "refs" "keys > "ref2bib.errs"
  300.     if(A==0)print "No author : Reference "refs" "keys > "ref2bib.errs"
  301.     if(D==0)print "No date : Reference "refs" "keys > "ref2bib.errs"
  302.     if( (!T)||(!A)||(!D))err=1;
  303.     # classify the reference
  304.     if(J){
  305.         #journal or conference
  306.         if(B||E||R)print "Journal & book?: Reference "refs" "keys > "ref2bib.errs"
  307.         if(C||I) {conf++
  308.             type = "Inproceedings"
  309.             }
  310.         else{
  311.             jour ++;
  312.             type = "Article"
  313.             }
  314.         if(!P) print "No page nos.? : Reference "refs" "keys > "ref2bib.errs"
  315.         if( B||E||R||(!P))err=1
  316.         if(err){
  317.             print "Journal reference in error" > "ref2bib.errs"
  318.             }
  319.         }
  320.     else
  321.     if(B){
  322.         # article in book
  323.         type = "Incollection"
  324.         bookart++
  325.         if(N||R||(!E)||(!I)||(!C)||(!P)||(V&&(!S)))err=1
  326.         if(!E) print "No editor? Reference "refs" " keys > "ref2bib.errs"
  327.         if(!I) print "No publisher? Reference "refs" " keys > "ref2bib.errs"
  328.         if(!C) print "No city? Reference "refs" " keys > "ref2bib.errs"
  329.         if(!P) print "No page nos.? Reference "refs" " keys > "ref2bib.errs"
  330.         if(V&&(!S))print "Volume but no Series Reference "refs" " keys > "ref2bib.errs"
  331.         if(N)print "Issue no.? Reference "refs" " keys > "ref2bib.errs"
  332.         if(R)print "Report? Reference "refs" " keys > "ref2bib.errs"
  333.         if(err){
  334.             print "Book reference in error" > "ref2bib.errs"
  335.             }
  336.         }
  337.     else if(R){
  338.         #report
  339.         type = "Techreport"
  340.         reps++
  341.         if(E||N)err=1
  342.         if(N)print "Issue no.? Reference "refs" " keys > "ref2bib.errs"
  343.         if(E) print "Editor? Reference "refs" " keys > "ref2bib.errs"
  344.         if(err){
  345.             print "Report reference in error" > "ref2bib.errs"
  346.             }
  347.         }
  348.     else if(I){
  349.         wholebook ++
  350.         type = "Book"
  351.         # book
  352.         if(N||R||E||(!C)||(V&&(!S)))err=1
  353.         if(!C) print "No city? Reference "refs" " keys > "ref2bib.errs"
  354.         if(N)print "Issue no.? Reference "refs" " keys > "ref2bib.errs"
  355.         if(E)print "Editor? Reference "refs" " keys > "ref2bib.errs"
  356.         if(V&&(!S))print "Volume but no Series Reference "refs" " keys > "ref2bib.errs"
  357.         if(err){
  358.             print "Book reference in error" > "ref2bib.errs"
  359.             }
  360.         }
  361.     else {
  362.         unclass ++
  363.         type = "Misc"
  364.         err=1
  365.             print "Unclassified reference in error" > "ref2bib.errs"
  366.         }
  367.  
  368.     # generate date
  369.     ndate = split(date,df)
  370.     if ( ndate > 2) print " Funny date " date > "ref2bib.errs"
  371.     if (ndate == 1 ) { df[2] = df[1]; df[1] = ""; }
  372.  
  373.  
  374.     # generate key
  375.     if(keys == "") keys = "ANON"
  376.     keys = keys substr(df[2],3,2)
  377.     if(keyused[keys] >=1) {
  378.         key_suffix = keyused[keys]++;
  379.         keys = keys addkey[key_suffix];
  380.         }
  381.     else keyused[keys] = 1
  382.     if (err)  {
  383.             print "Key: " keys > "ref2bib.errs"
  384.             if(A) for (i=1;i<=A;i++)
  385.                 print "%A " authors[i] > "ref2bib.errs"
  386.             if(T) print "%T " title > "ref2bib.errs"
  387.             if(J) print "%J "journal > "ref2bib.errs"
  388.             if(B) print "%B "book > "ref2bib.errs"
  389.             if(V) print "%V "volume > "ref2bib.errs"
  390.             if(N) print "%N "number > "ref2bib.errs"
  391.             if(I) print "%I "publisher > "ref2bib.errs"
  392.             if(C) print "%C "city > "ref2bib.errs"
  393.             if(E) for (i=1;i<=E;i++)print "%E "editor[i] > "ref2bib.errs"
  394.             if(S) print "%S "series > "ref2bib.errs"
  395.             if(P) print "%P "pages > "ref2bib.errs"
  396.             if(R) print "%R "report > "ref2bib.errs"
  397.             if(D) print "%D "date > "ref2bib.errs"
  398.             if(O) print "%O "other > "ref2bib.errs"
  399.             print "" > "ref2bib.errs"
  400.         }
  401.  
  402.     if(T){
  403.     twc = split(title,z)
  404.     title = z[1]; lt = length(z[1]);
  405.     for(i=2;i<=twc;i++) {
  406.         if(lt +length(z[i]) >= 55) {sc = "\n\t\t";lt = 0;}
  407.         else sc = " ";
  408.         title = title sc z[i]
  409.         lt += length(z[i]) + 1
  410.         }
  411.         }
  412.     if(O){
  413.     twc = split(other,z)
  414.     other = z[1]; lt = length(z[1]);
  415.     for(i=2;i<=twc;i++) {
  416.         if(lt + length(z[i]) >= 55) {sc = "\n\t\t";lt = 0;}
  417.         else sc = " ";
  418.         other = other sc z[i]
  419.         lt += length(z[i]) + 1
  420.         }
  421.         }
  422.     if(X){
  423.     twc = split(abstr,z)
  424.     abstr = z[1]; lt = length(z[1]);
  425.     for(i=2;i<=twc;i++) {
  426.         if(lt + length(z[i]) >= 55) {sc = "\n\t\t";lt = 0;}
  427.         else sc = " ";
  428.         abstr = abstr sc z[i]
  429.         lt += length(z[i]) + 1
  430.         }
  431.         }
  432.  
  433.     printf "@%s{\t%s",type,keys
  434.     if(A) {
  435.         printf ",\n\tAuthor = { %s",authors[1]
  436.         for(i=2;i<=A;i++) printf " and\n\t\t%s",authors[i]
  437.         printf " }"
  438.         }
  439.     if(T) printf ",\n\tTitle = { %s }",title
  440.     if(B) printf ",\n\tBooktitle = { %s }",book
  441.     if(E) {
  442.         printf ",\n\tEditor = { %s",editor[1]
  443.         for(i=2;i<=E;i++) printf " and\n\t\t%s",editor[i]
  444.         printf " }"
  445.         }
  446.     if(I) printf ",\n\tPublisher = { %s }",publisher
  447.     if(C) printf ",\n\tAddress = { %s }",city
  448.     if(J) { # substitute the journal abbreviations from the standard styles
  449.         journal = "{ " journal " }"
  450.         # {acmcs} {"ACM Computing Surveys"}
  451.         if ( journal ~ /Comp.* Sur/ ) journal = "acmcs"
  452.         # {acta} {"Acta Informatica"}
  453.         if ( journal ~ /Acta Inf/ ) journal = "acta"
  454.         # {cacm} {"Communications of the ACM"}
  455.         if ( journal ~ /Com.* ACM/ ) journal = "cacm"
  456.         if ( journal ~ /CACM/ ) journal = "cacm"
  457.         # {ibmjrd} {"IBM Journal of Research and Development"}
  458.         if ( journal ~ /IBM J.*R.*D/ ) journal = "ibmjrd"
  459.         # {ibmsj} {"IBM Systems Journal"}
  460.         if ( journal ~ /IBM Sy.*J/ ) journal = "ibmsj"
  461.         # {ieeese} {"IEEE Transactions on Software Engineering"}
  462.         if ( journal ~ /IEEE Tran.*Soft.*Eng/ ) journal = "ieeese"
  463.         # {ieeetc} {"IEEE Transactions on Computers"}
  464.         if ( journal ~ /IEEE Tran.*Computers/ ) journal = "ieeetc"
  465.         # {ieeetcad}
  466.         if ( journal ~ /IEEE Tran.*Comp.*Desig/ ) journal = "ieeetcad"
  467.         # {ipl} {"Information Processing Letters"}
  468.         if ( journal ~ /Inf.*Proc.*Lett/ ) journal = "ipl"
  469.         # {jacm} {"Journal of the ACM"}
  470.         if ( journal ~ /Jou.* ACM/ ) journal = "jacm"
  471.         if ( journal ~ /JACM/ ) journal = "jacm"
  472.         # {jcss} {"Journal of Computer and System Sciences"}
  473.         if ( journal ~ /J.*Comp.*Sys.*Sc/ ) journal = "jcss"
  474.         # {scp} {"Science of Computer Programming"}
  475.         if ( journal ~ /Sc.*Comp.*Prog/ ) journal = "scp"
  476.         # {sicomp} {"SIAM Journal on Computing"}
  477.         if ( journal ~ /SIAM .*Comp/ ) journal = "sicomp"
  478.         # {tocs} {"ACM Transactions on Computer Systems"}
  479.         if ( journal ~ /ACM Tran.*Comp.*Sys/ ) journal = "tocs"
  480.         # {tods} {"ACM Transactions on Database Systems"}
  481.         if ( journal ~ /ACM Tran.*Data.*Sys/ ) journal = "tods"
  482.         # {tog} {"ACM Transactions on Graphics"}
  483.         if ( journal ~ /ACM Tran.*Grap/ ) journal = "tog"
  484.         # {toms} {"ACM Transactions on Mathematical Software"}
  485.         if ( journal ~ /ACM Tran.*Math.*Soft/ ) journal = "toms"
  486.         # {toois} {"ACM Transactions on Office Information Systems"}
  487.         if ( journal ~ /ACM Tran.*Off.*Inf.*Sys/ ) journal = "toois"
  488.         # {toplas} {"ACM Transactions on Programming Languages and Systems"}
  489.         if ( journal ~ /ACM Tran.*Prog.*Lan.*Sys/ ) journal = "toplas"
  490.         # {tcs} {"Theoretical Computer Science"}
  491.         if ( journal ~ /Th.*Comp.*Sci/ ) journal = "tcs"
  492.  
  493.         printf ",\n\tJournal = %s",journal
  494.         }
  495.     if(V) printf ",\n\tVolume = { %s }",volume
  496.     if(N) printf ",\n\tNumber = { %s }",number
  497.     if(P) printf ",\n\tPages = { %s }",pages
  498.     if(O) printf ",\n\tNote = { %s }",other
  499.     if(R) printf ",\n\tNumber = { %s }",report
  500.     if(S) printf ",\n\tSeries = { %s }",series
  501.     if(df[1] != "")
  502.     printf ",\n\tMonth = { %s }",df[1]
  503.     if(D) printf ",\n\tYear = { %s }",df[2]
  504.     if(X) printf ",\n\tAnnote = { %s }",abstr
  505.     if(L) printf ",\n\tKey = { %s }",label
  506.     printf "\t}\n\n"
  507.  
  508.     A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;I=0;J=0;
  509.     K=0;L=0;M=0;N=0;O=0;P=0;Q=0;R=0;S=0;T=0;
  510.     U=0;V=0;W=0;X=0;Y=0;Z=0;
  511.     type = ""
  512.     book=""
  513.     title = ""
  514.     volume = ""
  515.     city = ""
  516.     date = ""
  517.     publisher = ""
  518.     journal = ""
  519.     number = ""
  520.     other = ""
  521.     page = ""
  522.     report = ""
  523.     series = ""
  524.     toterr +=err
  525.     rx++
  526.     }
  527.     err = 0
  528.     pr = NR
  529.     next
  530.     }
  531.  
  532. /^%T/    {
  533.     T ++; lastx = "T"
  534.     if(T>1){err=1
  535.         print "Two titles: Reference " rx > "ref2bib.errs"
  536.         print title > "ref2bib.errs"
  537.         }
  538.     title = substr($0,4)
  539.     next
  540.     }
  541.  
  542. /^%D/    {
  543.     D ++; lastx = "D"
  544.     if(D>1){err=1
  545.         print "Two dates: Reference " rx > "ref2bib.errs"
  546.         print date > "ref2bib.errs"
  547.         }
  548.     if(($NF<1900)||($NF>=2000)){err=1
  549.         print "Date error? : Reference " rx > "ref2bib.errs"
  550.         }
  551.     date = substr($0,4);
  552.     next
  553.     }
  554.  
  555. /^%P/    {
  556.     P ++; lastx = "P"
  557.     if(P>1){err=1
  558.         print "Two page nos? : Reference " rx > "ref2bib.errs"
  559.         print pages > "ref2bib.errs"
  560.         }
  561.     pages = substr($0,4)
  562.     next
  563.     }
  564.  
  565. /^%J/    {
  566.     J ++; lastx = "J"
  567.     if(J>1){err=1
  568.         print "Two journals: Reference " rx > "ref2bib.errs"
  569.         print journal > "ref2bib.errs"
  570.         }
  571.     journal = substr($0,4)
  572.     next
  573.     }
  574.  
  575. /^%V/    {
  576.     V ++; lastx = "V"
  577.     if(V>1){err=1
  578.         print "Two volumes: Reference " rx > "ref2bib.errs"
  579.         print volume > "ref2bib.errs"
  580.         }
  581.     volume = substr($0,4)
  582.     next
  583.     }
  584.  
  585. /^%N/    {
  586.     N ++; lastx = "N"
  587.     if(N>1){err=1
  588.         print "Two issue numbers: Reference " rx > "ref2bib.errs"
  589.         print number > "ref2bib.errs"
  590.         }
  591.     number = substr($0,4)
  592.     next
  593.     }
  594.  
  595. /^[^%]/    {
  596.     if( lastx == "A") authors[A] = authors[A]  " " $0
  597.     if( lastx == "B") book = book " " $0
  598.     if( lastx == "C") city = city " " $0
  599.     if( lastx == "D") date = date " " $0
  600.     if( lastx == "E") editor[E] = editor[E] " " $0
  601.     if( lastx == "I") publisher = publisher " " $0
  602.     if( lastx == "J") journal = journal " " $0
  603.     if( lastx == "L") label = label " " $0
  604.     if( lastx == "N") number = number " " $0
  605.     if( lastx == "O") other = other " " $0
  606.     if( lastx == "P") pages = pages " " $0
  607.     if( lastx == "R") report = report " " $0
  608.     if( lastx == "S") series = series " " $0
  609.     if( lastx == "T") title = title " " $0
  610.     if( lastx == "V") volume = volume " " $0
  611.     if( lastx == "X") abstr = abstr " " $0
  612.     next
  613.     }
  614.  
  615. /^%C/    {
  616.     C ++; lastx = "C"
  617.     if(C>1){err=1
  618.         print "Two cities: Reference " rx > "ref2bib.errs"
  619.         print city > "ref2bib.errs"
  620.         print " 2 cities " FILENAME, pr+1, NR > "ref2bib.errs"
  621.         }
  622.     city = substr($0,4)
  623.     next
  624.     }
  625.  
  626. /^%I/    {
  627.     I ++; lastx = "I"
  628.     if(I>1){err=1
  629.         print "Two publishers: Reference " rx > "ref2bib.errs"
  630.         print publisher > "ref2bib.errs"
  631.         }
  632.     publisher = substr($0,4)
  633.     next
  634.     }
  635.  
  636. /^%B/    {
  637.     B ++; lastx = "B"
  638.     if(B>1){err=1
  639.         print "Two books: Reference " rx > "ref2bib.errs"
  640.         print book > "ref2bib.errs"
  641.         }
  642.     book = substr($0,4)
  643.     next
  644.     }
  645.  
  646. /^%E/    {    # this really deals with 'bib' format
  647.         # refer only allows one %E fielsd, so we ought to
  648.         # split it somehow
  649.     E ++; lastx = "E"
  650.     editor[E] = substr($0,4)
  651.     next
  652.     }
  653.  
  654. /^%[^ABCDEIJKLNOPRSTVX]/    {
  655.         F ++; lastx = "F"; # should not get these
  656.         print "Unexpected flag: Reference " rx > "ref2bib.errs"
  657.         print $0 > "ref2bib.errs"
  658.         err = 1
  659.         next
  660.     }
  661.  
  662. /^%O/    {
  663.     O ++; lastx = "O"
  664.     if(O>1){err=1
  665.         print "Two others: Reference " rx > "ref2bib.errs"
  666.         print other > "ref2bib.errs"
  667.         }
  668.     other = substr($0,4)
  669.     next
  670.     }
  671.  
  672. /^%S/    {
  673.     S ++; lastx = "S"
  674.     if(S>1){err=1
  675.         print "Two series: Reference " rx > "ref2bib.errs"
  676.         print series > "ref2bib.errs"
  677.         }
  678.     series = substr($0,4)
  679.     next
  680.     }
  681.  
  682. /^%R/    {
  683.     R ++; lastx = "R"
  684.     if(R>1){err=1
  685.         print "Two reports: Reference " rx > "ref2bib.errs"
  686.         print report > "ref2bib.errs"
  687.         }
  688.     report = substr($0,4)
  689.     next
  690.     }
  691.  
  692. /^%X/    {
  693.     X ++; lastx = "X"
  694.     abstr = substr($0,4)
  695.     if(X>1){err=1
  696.         print "Two abstracts: Reference " rx > "ref2bib.errs"
  697.         }
  698.     next
  699.     }
  700.  
  701. /^%K/    {
  702.     lastx = "K"
  703.     next
  704.     }
  705. END    {
  706.     print refs " references" > "ref2bib.errs"
  707.     if(toterr) print toterr " erroneous" > "ref2bib.errs"
  708.     if(conf) print conf " conference papers" > "ref2bib.errs"
  709.     if(jour) print jour " journal articles" > "ref2bib.errs"
  710.     if(wholebook) print wholebook " books" > "ref2bib.errs"
  711.     if(totB) print totB " book articles" > "ref2bib.errs"
  712.     if(reps) print reps " reports" > "ref2bib.errs"
  713.     if(unclass) print unclass " Unclassified" > "ref2bib.errs"
  714.     if(totO) print totO " have additional information." > "ref2bib.errs"
  715.     if(totK) print totK " have additional keywords." > "ref2bib.errs"
  716.     if(totX) print totX " have abstracts/commentaries." > "ref2bib.errs"
  717.     print totA " authors" > "ref2bib.errs"
  718.     for(i=0;i<=MaxA;i++)if(acnt[i]){
  719.         print i, " authors ", acnt[i] > "ref2bib.errs"
  720.         av += i*acnt[i]
  721.         }
  722.     print "Average ", av/refs > "ref2bib.errs"
  723.     print totT " titles" > "ref2bib.errs"
  724.     print "Key frequencies" > "ref2bib.errs"
  725.     for(k in keyused) print k, keyused[k] > "ref2bib.errs"
  726.  
  727.     }
  728. ZZ
  729. sed -f ref2b$$.sed $* | awk -f ref2b$$.awk
  730. rm -f ref2b$$.sed ref2b$$.awk
  731. exit
  732.